# CCNCore::Scripting.pm
# Copyright (C) 2006  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information visit http://carrierclass.net/
#

use strict; use warnings;

package CCNv2::Scripting;
use CCNCore::Scripting;
use CCNCore::Home;
use Carp;


sub IF_CHANGED_restart_asterisk($)
{
    my $trigger = shift;
    IF_CHANGED $trigger, CCNCore::Home::manager.'/bin/provision/asterisk-restart.sh';
}

sub AST($)
{
    my $cmd = shift;
    croak "INTERNAL: AST(@_)" unless defined $cmd and $cmd !~ /'/;
    return qq(/usr/sbin/asterisk -r -n -x '$cmd' </dev/null || /usr/sbin/asterisk -r -n -x 'restart when convenient' || )
            .CCNCore::Home::manager.'/bin/provision/asterisk-restart.sh';
}

sub IF_CHANGED_restart_openser($)
{
    my $trigger = shift;
    IF_CHANGED $trigger, '/etc/init.d/openser stop; /usr/bin/killall -9 openser; /etc/init.d/openser start';
}

sub E164_CHANGED($$$)
{
    # croak 'INTERNAL ERROR: E164_CHANGED force_manager' if $force_manager;
    my ($from,$to,$command) = @_;
    CCNCore::Scripting::_COMMIT($from,"e164_changed('$from','$to',q($command));");
}

1;